#pragma once 
#include <sys/epoll.h>
#include <iostream>
#include <unistd.h>
#include <cerrno>

class Epoll{
public:
  static int Epoll_creat(int size = 128)
  {
    int epollfd = epoll_create(size);
    if(epollfd < 0)
    {
      std::cerr << "epoll create fail" << std::endl;
      exit(4);
    }

    return epollfd;
  }
  static void Addepoll(int epollfd, int fd, int event)
  { 
    struct epoll_event target;
    target.data.fd = fd;
    target.events = event;
    int ret = epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &target);
    if(ret < 0)
    {
      std::cerr << "epoll add fail" << std::endl;
      exit(5);
    }

  }
  static void Delepoll(int epollfd, int fd)
  {
    struct epoll_event event;
    event.data.fd = fd;
    int ret = epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &event);
    if(ret < 0)
    {
      std::cerr << "epoll del fail" << std::endl;
      exit(6);
    }
  }
  static void Modepoll(int epollfd, int fd, struct epoll_event &event)
  {
    int ret = epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, &event);
    if(ret < 0)
    {
      std::cerr << "epoll mod fail" << std::endl;
      exit(7);
    }
  }
  static int Waitepoll(int epollfd,struct epoll_event *event, int len)
  {
    int timeout = 1000;
    (void)timeout;
    int n = epoll_wait(epollfd,event,len,-1);
    
    return n;
  }
};
